package com.rpa.server.servicerpaserver.crawler.controller;

import com.rpa.secure.servicerpasecure.common.constant.MessageConstant;
import com.rpa.secure.servicerpasecure.common.exception.TaskException;
import com.rpa.secure.servicerpasecure.common.util.CurrentTeacherInfoUtil;
import com.rpa.server.servicerpaserver.crawler.entity.dto.ClazzCrawlerDto;
import com.rpa.server.servicerpaserver.crawler.operate.ClazzOperate;
import com.rpa.server.servicerpaserver.crawler.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ClazzController
 * @Description TODO
 * @Author 86152
 * @Date 2025/1/27 12:27
 * @Version 1.0
 **/
@Tag(name = "获取班级相关接口", description = "ClazzCrawlerController")
@Slf4j
@RestController
@RequestMapping("/crawler")
public class ClazzCrawlerController {
    @Autowired
    private ClazzOperate clazzOperate;
    @Autowired
    private UserService uerService;

    @PostMapping("/getClazz")
    @Operation(summary = "获取班级名单", description = "getClazz")
    public Boolean getClazz(@RequestBody ClazzCrawlerDto crawlerDto) {
        if (crawlerDto == null) {
            log.error("请求体中的 user 对象为空");
            throw new TaskException(MessageConstant.INVALID_REQUEST_BODY);
        }
        String rpaRegisterId = crawlerDto.getAccountId();
        String courseId =  crawlerDto.getCourseId();

        // 检查 rpaRegisterId 是否为空
        if (rpaRegisterId == null) {
            log.error("请求体中的 rpaRegisterId 字段为空");
            throw new TaskException(MessageConstant.INVALID_REQUEST_BODY);
        }

        log.info("当前用户id为：{}", CurrentTeacherInfoUtil.getCurrentTeacherId());
        log.info("接收到的 rpaRegisterId 为：{}", rpaRegisterId);
        return clazzOperate.getClass(rpaRegisterId,courseId).join();
    }
}
